

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Han Qiu">
  <meta name="keywords" content="">
  
    <meta name="description" content="一、开发环境性能优化1、优化打包构建速度1.1、HMRHMR：hot module replacement 热模块替换 &#x2F; 模块热替换。  作用：一个模块发生变化，只会重新打包这一模块，而不是重新打包所有模块，极大提升构建速度。 样式文件：可以使用 HMR 功能，因为style-loader内部实现了。 js文件：默认不能使用 HMR 功能 -&gt; 需要修改js代码，添加支持 HMR 功能的代">
<meta property="og:type" content="article">
<meta property="og:title" content="webpack性能优化">
<meta property="og:url" content="http://example.com/2022/01/06/webpack%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/index.html">
<meta property="og:site_name" content="寒秋の博客">
<meta property="og:description" content="一、开发环境性能优化1、优化打包构建速度1.1、HMRHMR：hot module replacement 热模块替换 &#x2F; 模块热替换。  作用：一个模块发生变化，只会重新打包这一模块，而不是重新打包所有模块，极大提升构建速度。 样式文件：可以使用 HMR 功能，因为style-loader内部实现了。 js文件：默认不能使用 HMR 功能 -&gt; 需要修改js代码，添加支持 HMR 功能的代">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-01-06T03:44:25.000Z">
<meta property="article:modified_time" content="2022-01-06T03:46:27.185Z">
<meta property="article:author" content="Han Qiu">
<meta property="article:tag" content="webpack">
<meta name="twitter:card" content="summary_large_image">
  
  
  <title>webpack性能优化 - 寒秋の博客</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.8.14","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 6.0.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>blogs</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="webpack性能优化">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2022-01-06 11:44" pubdate>
        2022年1月6日 中午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      3.9k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      33 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">webpack性能优化</h1>
            
            <div class="markdown-body">
              <h3 id="一、开发环境性能优化"><a href="#一、开发环境性能优化" class="headerlink" title="一、开发环境性能优化"></a>一、开发环境性能优化</h3><h4 id="1、优化打包构建速度"><a href="#1、优化打包构建速度" class="headerlink" title="1、优化打包构建速度"></a>1、优化打包构建速度</h4><h5 id="1-1、HMR"><a href="#1-1、HMR" class="headerlink" title="1.1、HMR"></a>1.1、HMR</h5><p>HMR：hot module replacement 热模块替换 / 模块热替换。</p>
<ul>
<li>作用：一个模块发生变化，只会重新打包这一模块，而不是重新打包所有模块，极大提升构建速度。<ul>
<li>样式文件：可以使用 HMR 功能，因为style-loader内部实现了。</li>
<li>js文件：默认不能使用 HMR 功能 -&gt; 需要修改js代码，添加支持 HMR 功能的代码。<ul>
<li>注意：HMR 功能对 js 的处理，只能处理非入口 js 文件的其他文件。</li>
</ul>
</li>
<li>html文件：默认不能使用 HMR 功能，同时会导致问题： html文件不能热更新了（修改后不会重新编译，刷新浏览器）。<ul>
<li>解决：修改entry入口，将html文件引入。</li>
<li>由于html文件只有一个，因此不用做 HMR 功能。</li>
</ul>
</li>
</ul>
</li>
</ul>
<h5 id="1-2、source-map"><a href="#1-2、source-map" class="headerlink" title="1.2、source-map"></a>1.2、source-map</h5><p>source-map：一种提供源代码到构建后代码映射的技术（如果构建后代码出错了，通过映射可以追踪源代码错误）</p>
<figure class="highlight js"><table><tr><td class="gutter"><div class="code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></div></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// 直接在 webpack.config.js 中添加 devtool 即可开启source-map</span><br><span class="hljs-attr">devtool</span>: <span class="hljs-string">&#x27;source-map&#x27;</span><br></code></pre></td></tr></table></figure>
<p>devtool 取值为 <code>[ inline- | hidden- | eval- ] [ nosources- ] [ cheap- [ module- ] ] source-map</code></p>
<hr>
<ul>
<li>内联和外部的区别：<ul>
<li>1、外部生成了文件，内联没有</li>
<li>2、内联构建速度更快    </li>
</ul>
</li>
</ul>
<hr>
<ul>
<li>source-map：外部<ul>
<li>错误代码准确信息 和 源代码的错误位置</li>
</ul>
</li>
<li>inline-source-map：内联<ul>
<li>只生成一个内联source-map</li>
<li>错误代码准确信息 和 源代码的错误位置</li>
</ul>
</li>
<li>hidden-source-map：外部<ul>
<li>错误代码的错误原因，但是没有源代码错误位置，只能提示到构建后代码的错误位置</li>
</ul>
</li>
<li>eval-source-map：内联<ul>
<li>每一个文件都生成对应的source-map，都在eval</li>
<li>错误代码准确信息 和 源代码的错误位置</li>
</ul>
</li>
<li>nosources-source-map：外部<ul>
<li>错误代码的错误信息，但没有任何源代码信息</li>
</ul>
</li>
<li>cheap-source-map：外部<ul>
<li>错误代码准确信息 和 源代码的错误位置</li>
<li>只能精确到行（当错误代码与正确代码在同一行时，整行标志整行，包含正确代码）</li>
</ul>
</li>
<li>cheap-module-source-map：外部<ul>
<li>错误代码准确信息 和 源代码的错误位置</li>
<li>module会将 loader 的 source map 加入</li>
</ul>
</li>
</ul>
<hr>
<ul>
<li>开发环境：要求速度快，调试更友好<ul>
<li>速度快（eval &gt; inline &gt; cheap &gt; …）<ul>
<li>eval-cheap-source-map</li>
<li>eval-source-map</li>
</ul>
</li>
<li>调试更友好<ul>
<li>source-map</li>
<li>cheap-module-source-map</li>
<li>cheap-source-map</li>
</ul>
</li>
<li>–&gt; eval-source-map / eval-cheap-module-source-map</li>
</ul>
</li>
<li>生产环境：源代码是否隐藏？调试是否要友好？<ul>
<li>内联会让代码体积变大，所以生产环境不用内联</li>
<li>nosources-source-map 源代码和构建后代码全部隐藏</li>
<li>hidden-source-map 只隐藏源代码，会提示构建后代码错误信息</li>
<li>–&gt; source-map / cheap-module-source-map</li>
</ul>
</li>
</ul>
<h5 id="1-3、oneOf"><a href="#1-3、oneOf" class="headerlink" title="1.3、oneOf"></a>1.3、oneOf</h5><h5 id="1-4、缓存"><a href="#1-4、缓存" class="headerlink" title="1.4、缓存"></a>1.4、缓存</h5><ul>
<li>babel缓存（让第二次打包构建速度更快）<ul>
<li>cacheDirectory: true</li>
</ul>
</li>
<li>文件资源缓存（让代码上线运行缓存，加快相应速度）<ul>
<li>hash：每次 webpack 构建时会生成一个唯一的 hash 值。<ul>
<li>问题：因为 js 和 css 同时使用一个 hash 值，如果重新打包，会导致所有缓存失效。（可能只改动一个文件）</li>
</ul>
</li>
<li>chunkhash：根据 chunk 生成的 hash 值。如果打包来源于同一个 chunk，那么 hash 值就一样。<ul>
<li>问题：js 和 css 的 hash 值还是一样的，因为 css 是在 js 中被引入的，所以同属于一个chunk</li>
</ul>
</li>
<li>contenthash：根据文件的内容生成 hash 值，不同文件 hash 值一定不一样 </li>
</ul>
</li>
</ul>
<h5 id="1-5、tree-shaking"><a href="#1-5、tree-shaking" class="headerlink" title="1.5、tree shaking"></a>1.5、tree shaking</h5><p>tree shaking：去除应用程序中没有使用的代码，让代码体积更小</p>
<ul>
<li>前提：1、必须使用 ES6 模块化    2、开启 production 环境</li>
<li>作用：减少代码体积</li>
</ul>
<hr>
<ul>
<li>可能由于 webpack 版本问题，将 css 等文件去除，在 package.json 中配置 “sideEffects”: false 模拟：<ul>
<li>“sideEffects”: false 所有代码都没有副作用（都可以进行tree shaking）</li>
<li>问题：可能会把 css / @babel/polyfill 等（副作用）文件去除 </li>
<li>解决：”sideEffects”: [“*.css”, “*.less”]，最好添加该配置，否则可能因为 webpack 版本问题去除 css 等文件</li>
</ul>
</li>
</ul>
<h5 id="1-6、code-split"><a href="#1-6、code-split" class="headerlink" title="1.6、code split"></a>1.6、code split</h5><p>code split：将打包生成的一个文件分割为多个文件</p>
<ul>
<li>方案一：单入口 / 多入口文件，每个入口打包成一个文件</li>
<li>方案二：webpack.config.js 配置中添加 optimization（一般都是单入口文件，该方案使用较少）</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// 1、可以将node_modules中代码单独打包一个chunk最终输出</span><br><span class="hljs-comment">// 2、自动分析多入口chunk中，有没有公共的文件。如果有，会打包成一个单独chunk</span><br><span class="hljs-attr">optimization</span>: &#123;<br>    <span class="hljs-attr">splitChunks</span>: &#123;<br>        <span class="hljs-attr">chunks</span>: <span class="hljs-string">&#x27;all&#x27;</span><br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>方案三：单入口，配置中添加 optimization，并通过js代码，让某个文件被单独打包成一个chunk</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// import动态导入语法，能让某个文件单独打包</span><br><span class="hljs-keyword">import</span>(<span class="hljs-comment">/* webpackChunkName: &#x27;test&#x27; */</span><span class="hljs-string">&#x27;.test&#x27;</span>)<br>    .then(<span class="hljs-function">(<span class="hljs-params">&#123; mul, count&#125;</span>) =&gt;</span> &#123;<br>        <span class="hljs-comment">// 文件加载成功</span><br>        <span class="hljs-built_in">console</span>.log(mul(<span class="hljs-number">2</span>, <span class="hljs-number">5</span>));<br>    &#125;)<br>    .catch(<span class="hljs-function">() =&gt;</span> &#123;<br>        <span class="hljs-comment">// 文件加载失败</span><br>    &#125;);<br></code></pre></td></tr></table></figure>

<h5 id="1-7、懒加载和预加载"><a href="#1-7、懒加载和预加载" class="headerlink" title="1.7、懒加载和预加载"></a>1.7、懒加载和预加载</h5><ul>
<li>懒加载：当文件需要使用时才加载</li>
<li>预加载 prefetch（会有兼容性问题）：会在使用之前，提前加载js文件</li>
<li>正常加载可以认为是并行加载（同一时间加载多个文件），而预加载是等其他资源加载完毕，浏览器空闲了，再偷偷加载资源</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">&#x27;btn&#x27;</span>).onclick = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>&#123;<br>    <span class="hljs-comment">// 点击时，动态引入为懒加载，设置 webpackPrefetch: true 为预加载</span><br>    <span class="hljs-keyword">import</span>(<span class="hljs-comment">/* webpackChunkName: &#x27;test&#x27;, webpackPrefetch: true */</span><span class="hljs-string">&#x27;./test&#x27;</span>)<br>        .then(<span class="hljs-function">(<span class="hljs-params">&#123; mul &#125;</span>) =&gt;</span> &#123;<br>            <span class="hljs-built_in">console</span>.log(mul(<span class="hljs-number">2</span>, <span class="hljs-number">5</span>));<br>        &#125;);<br>&#125;;<br></code></pre></td></tr></table></figure>

<h5 id="1-8、PWA"><a href="#1-8、PWA" class="headerlink" title="1.8、PWA"></a>1.8、PWA</h5><p>PWA：渐进式网络开发应用程序（离线可访问）。webpack中使用workbox-webpack-plugin插件</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// 在webpack中使用workbox-webpack-plugin插件</span><br><span class="hljs-keyword">const</span> WorkboxWebpackPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;workbox-webpack-plugin&#x27;</span>);<br><br><span class="hljs-built_in">module</span>.exports = &#123;<br>    <span class="hljs-attr">plugins</span>: [<br>        <span class="hljs-keyword">new</span> WorkboxWebpackPlugin.GenerateSW(&#123;<br>            <span class="hljs-comment">/*</span><br><span class="hljs-comment">                1、帮助 serviceworker 快速启动</span><br><span class="hljs-comment">                2、删除旧的 serviceworker</span><br><span class="hljs-comment">                </span><br><span class="hljs-comment">                打包时会自动生成一个 serviceworker 配置文件</span><br><span class="hljs-comment">            */</span><br>            <span class="hljs-attr">clientsClain</span>: <span class="hljs-literal">true</span>,<br>            <span class="hljs-attr">skipWaiting</span>: <span class="hljs-literal">true</span><br>        &#125;)<br>    ]<br>&#125;<br><br><span class="hljs-comment">// 在入口文件中注册 serviceworker</span><br><span class="hljs-comment">// 注册 serviceworker，并处理兼容性问题</span><br><span class="hljs-comment">/*</span><br><span class="hljs-comment">    注意： </span><br><span class="hljs-comment">    1、eslint不认识 window、navigator 全局变量</span><br><span class="hljs-comment">        解决：需要修改 package.json 中 eslintConfig 配置</span><br><span class="hljs-comment">        &quot;env&quot;: &#123;</span><br><span class="hljs-comment">            // 支持浏览器端全局变量</span><br><span class="hljs-comment">            &quot;browser&quot;: true</span><br><span class="hljs-comment">        &#125;</span><br><span class="hljs-comment">    2、sw代码必须运行在服务器上</span><br><span class="hljs-comment">        --&gt; 快速创建服务器库 serve</span><br><span class="hljs-comment">            npm i serve -g</span><br><span class="hljs-comment">            serve -s build 启动服务器，将build目录下所有资源作为静态资源暴露出去    </span><br><span class="hljs-comment">*/</span><br><span class="hljs-keyword">if</span> (<span class="hljs-string">&#x27;serviceWorker&#x27;</span> <span class="hljs-keyword">in</span> navigator) &#123;<br>    <span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">&#x27;load&#x27;</span>, <span class="hljs-function">() =&gt;</span> &#123;<br>        navigator.serviceWorker<br>            .register(<span class="hljs-string">&#x27;/service-worker.js&#x27;</span>)<br>            .then(<span class="hljs-function">() =&gt;</span> &#123;<br>                <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;sw注册成功了&#x27;</span>);<br>            &#125;)<br>            .catch(<span class="hljs-function">() =&gt;</span> &#123;<br>                <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;sw注册失败了&#x27;</span>);<br>            &#125;);<br>    &#125;);<br>&#125;<br></code></pre></td></tr></table></figure>

<h5 id="1-9、多进程打包"><a href="#1-9、多进程打包" class="headerlink" title="1.9、多进程打包"></a>1.9、多进程打包</h5><p>使用 thread-loader 插件</p>
<h5 id="1-10、externals"><a href="#1-10、externals" class="headerlink" title="1,10、externals"></a>1,10、externals</h5><h5 id="1-11、dll"><a href="#1-11、dll" class="headerlink" title="1.11、dll"></a>1.11、dll</h5><h4 id="2、优化代码调试"><a href="#2、优化代码调试" class="headerlink" title="2、优化代码调试"></a>2、优化代码调试</h4><h3 id="二、生产环境性能优化"><a href="#二、生产环境性能优化" class="headerlink" title="二、生产环境性能优化"></a>二、生产环境性能优化</h3><h4 id="1、优化打包构建速度-1"><a href="#1、优化打包构建速度-1" class="headerlink" title="1、优化打包构建速度"></a>1、优化打包构建速度</h4><h4 id="2、优化代码运行的性能"><a href="#2、优化代码运行的性能" class="headerlink" title="2、优化代码运行的性能"></a>2、优化代码运行的性能</h4>
            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E6%89%93%E5%8C%85%E5%B7%A5%E5%85%B7/">打包工具</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/webpack/">webpack</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/01/06/gulp%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%EF%BC%88%E7%89%88%E6%9C%AC3-9-1%EF%BC%89/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">gulp基本使用（版本3.9.1）</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/01/06/dos%E4%BF%AE%E6%94%B9%E9%BB%98%E8%AE%A4%E7%BC%96%E7%A0%81%E6%A0%BC%E5%BC%8F/">
                        <span class="hidden-mobile">dos修改默认编码格式</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
